<template>
  <view class="bottom-nav-h5-demo">
    <!-- 页面内容 -->
    <view class="demo-content">
      <!-- 头部区域 -->
      <view class="demo-header">
        <view class="header-content">
          <text class="demo-title">H5端底部导航</text>
          <text class="demo-subtitle">专为H5端优化的底部导航组件</text>
          <view class="demo-badges">
            <view class="badge">响应式</view>
            <view class="badge">主题切换</view>
            <view class="badge">动画效果</view>
          </view>
        </view>
      </view>
      
      <!-- 功能演示区域 -->
      <view class="demo-sections">
        <!-- 主题选择 -->
        <view class="demo-section">
          <view class="section-header">
            <text class="section-title">🎨 主题选择</text>
            <text class="section-desc">选择不同的主题色彩</text>
          </view>
          <view class="theme-grid">
            <view 
              v-for="theme in themes" 
              :key="theme.value"
              class="theme-card"
              :class="{ 'theme-card--active': currentTheme === theme.value }"
              @click="changeTheme(theme.value)"
            >
              <view class="theme-preview" :style="{ backgroundColor: theme.color }">
                <view class="theme-icon">{{ theme.icon }}</view>
              </view>
              <text class="theme-name">{{ theme.name }}</text>
              <text class="theme-desc">{{ theme.desc }}</text>
            </view>
          </view>
        </view>
        
        <!-- 配置选项 -->
        <view class="demo-section">
          <view class="section-header">
            <text class="section-title">⚙️ 配置选项</text>
            <text class="section-desc">自定义导航行为</text>
          </view>
          <view class="config-grid">
            <view class="config-card">
              <view class="config-header">
                <text class="config-title">显示设置</text>
              </view>
              <view class="config-options">
                <view class="config-option">
                  <text class="config-label">固定定位</text>
                  <switch :checked="navConfig.fixed" @change="updateConfig('fixed', $event.detail.value)" />
                </view>
                <view class="config-option">
                  <text class="config-label">安全区域</text>
                  <switch :checked="navConfig.safeArea" @change="updateConfig('safeArea', $event.detail.value)" />
                </view>
                <view class="config-option">
                  <text class="config-label">激活指示器</text>
                  <switch :checked="navConfig.showIndicator" @change="updateConfig('showIndicator', $event.detail.value)" />
                </view>
                <view class="config-option">
                  <text class="config-label">点击动画</text>
                  <switch :checked="navConfig.enableAnimation" @change="updateConfig('enableAnimation', $event.detail.value)" />
                </view>
              </view>
            </view>
            
            <view class="config-card">
              <view class="config-header">
                <text class="config-title">徽章设置</text>
              </view>
              <view class="config-options">
                <view class="config-option">
                  <text class="config-label">显示徽章</text>
                  <switch :checked="navConfig.showBadge" @change="updateConfig('showBadge', $event.detail.value)" />
                </view>
                <view class="config-option">
                  <text class="config-label">显示红点</text>
                  <switch :checked="navConfig.showDot" @change="updateConfig('showDot', $event.detail.value)" />
                </view>
                <view class="config-option">
                  <text class="config-label">徽章数量</text>
                  <input 
                    v-model="badgeCount" 
                    type="number" 
                    class="config-input"
                    @input="updateBadgeCount"
                  />
                </view>
              </view>
            </view>
          </view>
        </view>
        
        <!-- 当前状态 -->
        <view class="demo-section">
          <view class="section-header">
            <text class="section-title">📱 当前状态</text>
            <text class="section-desc">实时显示导航状态</text>
          </view>
          <view class="status-cards">
            <view class="status-card">
              <view class="status-icon">📍</view>
              <view class="status-content">
                <text class="status-title">当前页面</text>
                <text class="status-value">{{ currentPageInfo.text }}</text>
              </view>
            </view>
            <view class="status-card">
              <view class="status-icon">🎨</view>
              <view class="status-content">
                <text class="status-title">当前主题</text>
                <text class="status-value">{{ currentThemeInfo.name }}</text>
              </view>
            </view>
            <view class="status-card">
              <view class="status-icon">⚡</view>
              <view class="status-content">
                <text class="status-title">点击次数</text>
                <text class="status-value">{{ clickCount }}</text>
              </view>
            </view>
          </view>
        </view>
        
        <!-- 模拟内容 -->
        <view class="demo-section">
          <view class="section-header">
            <text class="section-title">📄 模拟内容</text>
            <text class="section-desc">用于测试固定定位效果</text>
          </view>
          <view class="content-grid">
            <view class="content-card" v-for="i in 8" :key="i">
              <view class="card-header">
                <text class="card-title">内容卡片 {{ i }}</text>
                <view class="card-badge">{{ i }}</view>
              </view>
              <text class="card-desc">
                这是模拟的内容区域，用于展示底部导航的固定效果。
                在H5端，固定定位的底部导航会始终显示在屏幕底部。
              </text>
              <view class="card-footer">
                <text class="card-time">{{ getCurrentTime() }}</text>
                <view class="card-actions">
                  <text class="card-action">👍</text>
                  <text class="card-action">💬</text>
                  <text class="card-action">📤</text>
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
    
    <!-- 底部导航 -->
    <bottom-nav-h5
      :items="navItems"
      :current="currentNavIndex"
      :fixed="navConfig.fixed"
      :safe-area="navConfig.safeArea"
      :theme="currentTheme"
      :show-indicator="navConfig.showIndicator"
      :enable-animation="navConfig.enableAnimation"
      @change="handleNavChange"
      @tap="handleNavTap"
    />
  </view>
</template>

<script>
import BottomNavH5 from '@/components/bottom-nav-h5/bottom-nav-h5.vue'

export default {
  name: 'BottomNavH5Demo',
  components: {
    BottomNavH5
  },
  data() {
    return {
      currentNavIndex: 0,
      currentTheme: 'blue',
      clickCount: 0,
      badgeCount: 3,
      themes: [
        { 
          name: '经典蓝', 
          value: 'blue', 
          color: '#0A2463', 
          icon: '🔵',
          desc: '专业稳重'
        },
        { 
          name: '活力橙', 
          value: 'orange', 
          color: '#FF6B35', 
          icon: '🟠',
          desc: '活力四射'
        },
        { 
          name: '自然绿', 
          value: 'green', 
          color: '#00C851', 
          icon: '🟢',
          desc: '清新自然'
        },
        { 
          name: '神秘紫', 
          value: 'purple', 
          color: '#8B5CF6', 
          icon: '🟣',
          desc: '神秘优雅'
        }
      ],
      navConfig: {
        fixed: true,
        safeArea: true,
        showIndicator: true,
        enableAnimation: true,
        showBadge: true,
        showDot: true
      },
      navItems: [
        {
          text: '首页',
          iconText: '🏠',
          pagePath: '/pages/index/index',
          badge: '',
          dot: false
        },
        {
          text: '智能评估',
          iconText: '🤖',
          pagePath: '/pages/smart-evaluation/index',
          badge: '',
          dot: false
        },
        {
          text: '工具',
          iconText: '🛠️',
          pagePath: '/pages/tools/index',
          badge: '3',
          dot: false
        },
        {
          text: '进度',
          iconText: '📊',
          pagePath: '/pages/progress-tracking/index',
          badge: '',
          dot: true
        },
        {
          text: '我的',
          iconText: '👤',
          pagePath: '/pages/personal-center/index',
          badge: '',
          dot: false
        }
      ]
    }
  },
  computed: {
    currentPageInfo() {
      return this.navItems[this.currentNavIndex] || this.navItems[0]
    },
    currentThemeInfo() {
      return this.themes.find(t => t.value === this.currentTheme) || this.themes[0]
    }
  },
  methods: {
    changeTheme(theme) {
      this.currentTheme = theme
      uni.showToast({
        title: `已切换到${this.themes.find(t => t.value === theme)?.name}`,
        icon: 'success',
        duration: 1500
      })
    },
    
    updateConfig(key, value) {
      this.navConfig[key] = value
      
      // 更新导航项配置
      if (key === 'showBadge') {
        this.navItems = this.navItems.map((item, index) => ({
          ...item,
          badge: value && index === 2 ? this.badgeCount.toString() : ''
        }))
      }
      
      if (key === 'showDot') {
        this.navItems = this.navItems.map((item, index) => ({
          ...item,
          dot: value && index === 3
        }))
      }
    },
    
    updateBadgeCount() {
      if (this.navConfig.showBadge) {
        this.navItems = this.navItems.map((item, index) => ({
          ...item,
          badge: index === 2 ? this.badgeCount.toString() : item.badge
        }))
      }
    },
    
    handleNavChange(event) {
      this.currentNavIndex = event.index
      this.clickCount++
      console.log('导航切换:', event)
      
      uni.showToast({
        title: `切换到${event.item.text}`,
        icon: 'none',
        duration: 1000
      })
    },
    
    handleNavTap() {
      this.clickCount++
    },
    
    getCurrentTime() {
      const now = new Date()
      return now.toLocaleTimeString('zh-CN', { 
        hour: '2-digit', 
        minute: '2-digit' 
      })
    }
  },
  
  onLoad() {
    uni.setNavigationBarTitle({
      title: 'H5底部导航演示'
    })
  },
  
  onShow() {
    // 页面显示时更新徽章数量
    this.updateBadgeCount()
  }
}
</script>

<style lang="scss" scoped>
.bottom-nav-h5-demo {
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  padding-bottom: 100px; // 为固定底部导航留出空间
}

.demo-content {
  padding: 0;
}

.demo-header {
  background: linear-gradient(135deg, #0A2463 0%, #1E3A8A 50%, #3B82F6 100%);
  color: white;
  padding: 40px 20px;
  text-align: center;
  position: relative;
  overflow: hidden;
  
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="25" cy="25" r="1" fill="white" opacity="0.1"/><circle cx="75" cy="75" r="1" fill="white" opacity="0.1"/><circle cx="50" cy="10" r="0.5" fill="white" opacity="0.1"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
    opacity: 0.3;
  }
}

.header-content {
  position: relative;
  z-index: 1;
}

.demo-title {
  display: block;
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.demo-subtitle {
  display: block;
  font-size: 16px;
  opacity: 0.9;
  margin-bottom: 20px;
}

.demo-badges {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.demo-sections {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.demo-section {
  background: white;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.section-header {
  margin-bottom: 20px;
}

.section-title {
  display: block;
  font-size: 20px;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 4px;
}

.section-desc {
  display: block;
  font-size: 14px;
  color: #6b7280;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
}

.theme-card {
  padding: 20px;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  background: #fafafa;
  
  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  }
  
  &--active {
    border-color: #0A2463;
    background: rgba(10, 36, 99, 0.05);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(10, 36, 99, 0.2);
  }
}

.theme-preview {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.theme-icon {
  font-size: 20px;
}

.theme-name {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 4px;
}

.theme-desc {
  display: block;
  font-size: 12px;
  color: #6b7280;
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

.config-card {
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  overflow: hidden;
  background: #fafafa;
}

.config-header {
  background: #f8fafc;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
}

.config-title {
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
}

.config-options {
  padding: 20px;
}

.config-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #f3f4f6;
  
  &:last-child {
    border-bottom: none;
  }
}

.config-label {
  font-size: 14px;
  color: #374151;
  font-weight: 500;
}

.config-input {
  width: 60px;
  padding: 4px 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  text-align: center;
  font-size: 14px;
}

.status-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.status-card {
  display: flex;
  align-items: center;
  padding: 20px;
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  border-radius: 12px;
  border: 1px solid #e5e7eb;
}

.status-icon {
  font-size: 24px;
  margin-right: 16px;
}

.status-content {
  flex: 1;
}

.status-title {
  display: block;
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 4px;
}

.status-value {
  display: block;
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
}

.content-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

.content-card {
  padding: 20px;
  background: #f8fafc;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  transition: all 0.3s ease;
  
  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  }
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
}

.card-badge {
  background: #0A2463;
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.card-desc {
  font-size: 14px;
  color: #6b7280;
  line-height: 1.5;
  margin-bottom: 16px;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-time {
  font-size: 12px;
  color: #9ca3af;
}

.card-actions {
  display: flex;
  gap: 12px;
}

.card-action {
  font-size: 16px;
  cursor: pointer;
  transition: transform 0.2s ease;
  
  &:hover {
    transform: scale(1.2);
  }
}

// 响应式设计
@media (max-width: 480px) {
  .demo-header {
    padding: 30px 16px;
  }
  
  .demo-title {
    font-size: 24px;
  }
  
  .demo-subtitle {
    font-size: 14px;
  }
  
  .demo-sections {
    padding: 16px;
    gap: 20px;
  }
  
  .demo-section {
    padding: 20px 16px;
  }
  
  .theme-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  
  .config-grid {
    grid-template-columns: 1fr;
  }
  
  .status-cards {
    grid-template-columns: 1fr;
  }
  
  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 768px) {
  .demo-sections {
    max-width: 1200px;
    margin: 0 auto;
  }
  
  .theme-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  
  .config-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

// 深色模式支持
@media (prefers-color-scheme: dark) {
  .bottom-nav-h5-demo {
    background: linear-gradient(135deg, #111827 0%, #1f2937 100%);
  }
  
  .demo-section {
    background: #1f2937;
    border-color: #374151;
  }
  
  .section-title {
    color: #f9fafb;
  }
  
  .section-desc {
    color: #9ca3af;
  }
  
  .theme-card {
    background: #111827;
    border-color: #374151;
    
    &--active {
      background: rgba(59, 130, 246, 0.1);
      border-color: #3b82f6;
    }
  }
  
  .config-card {
    background: #111827;
    border-color: #374151;
  }
  
  .config-header {
    background: #111827;
    border-color: #374151;
  }
  
  .config-title {
    color: #f9fafb;
  }
  
  .config-label {
    color: #d1d5db;
  }
  
  .status-card {
    background: linear-gradient(135deg, #111827 0%, #1f2937 100%);
    border-color: #374151;
  }
  
  .status-title {
    color: #9ca3af;
  }
  
  .status-value {
    color: #f9fafb;
  }
  
  .content-card {
    background: #111827;
    border-color: #374151;
  }
  
  .card-title {
    color: #f9fafb;
  }
  
  .card-desc {
    color: #9ca3af;
  }
  
  .card-time {
    color: #6b7280;
  }
}
</style>
